#define _CRT_SECURE_NO_WARNINGS

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */

void PreOrder(struct TreeNode* root, int* res, int* returnSize)
{
    if (root == NULL)
        return;
    res[(*returnSize)++] = root->val;
    PreOrder(root->left, res, returnSize);
    PreOrder(root->right, res, returnSize);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int* res = (int*)malloc(sizeof(int) * 100);
    *returnSize = 0;
    PreOrder(root, res, returnSize);
    return res;
}